<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 pageEncoding="ISO-8859-1"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Hashtable"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Enumeration"%>
<%@page import="eBrain.beans.Item"%>
<%@page import="eBrain.beans.User"%>
<%@page import="eBrain.beans.Bid"%>
<%@page import="eBrain.beans.Sales"%>
<%@page import="eBrain.beans.CategorySales"%>
<jsp:useBean id="dataManager" scope="application"
  class="eBrain.model.DataManager"/>
 <%String base = (String)application.getAttribute("base"); %>
   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="eBrain.model.SalesWorker"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="/eBrain/css/eshop.css" type="text/css"/>
    <script type="text/javascript" src="dojo/dojo.js"
        djConfig="parseOnLoad: true"></script>
        <script type="text/javascript" src="jscript/saleStat.js"></script>
</head>
<body>
<jsp:include page="TopMenu.jsp" flush="true"/>
<jsp:include page="LeftMenu.jsp" flush="true"/>
<div class="meBrainMenu">
</div>


 <div class="content">
 	 
 
	<h>eBrain Sales Statistic</h>
	
	<h>Sales per Category</h>
	<select id="categoryselect" name="category" onchange="setCategory()">
     	<%
     	Hashtable cats  = dataManager.getAllCategories(); 
     	Enumeration<String> categoryIds = cats.keys();
        while (categoryIds.hasMoreElements()) {
          Object categoryId = categoryIds.nextElement();
     	%>
     	<option value="<%=categoryId.toString()%>"><%=cats.get(categoryId)%></option>
     	<%}%>
    </select>
      	<%if(request.getAttribute("categoryQuery")!=null){
    CategorySales catsales = (CategorySales)request.getAttribute("categoryQuery");%>
     <br><h><%="for Category: " + cats.get(request.getAttribute("selectedCategory"))%></h>
     <br>	
    <table>
    <tr>
    <td>Fees</td> <td>Total Sales</td><td></td> <td></td><td></td> <td></td>
    </tr>
    <tr>
    <td><%=catsales.getCategorySalesFees() %></td> <td><%=catsales.getCategorySalesSum()%></td><td></td> <td></td><td></td> <td></td>
    </tr>
    
    </table>
    <%} else{ 
    		
     		ArrayList<CategorySales> categoryAll = (ArrayList<CategorySales>)request.getAttribute("categoryAll");
			Iterator it = categoryAll.iterator();
	%>	
		<table>
    <tr>
    <td>Fees</td> <td>Total Sales</td>
    </tr>
	<% 	
		while(it.hasNext()){
		CategorySales oneSalesWorker = (CategorySales)it.next();
		
    %>
    	<tr>
    <td><%=oneSalesWorker.getCategoryName() %></td><td><%=oneSalesWorker.getCategorySalesFees() %></td> <td><%=oneSalesWorker.getCategorySalesSum()%></td>
    </tr>
    
    
    <%}%>
    </table>
    <%}%>
    
    
     
	<br>
	<h>Sales per User</h>
    User: <select id="userselect" name="users" onchange="setUsername()">
     	<%
     	ArrayList<String> users  = dataManager.getUsernames(); 
        Iterator<String> iterator = users.iterator();
        while (iterator.hasNext()) {
          String toadd = (String)iterator.next().trim();
     	%>
     	<option value="<%=toadd%>"><%=toadd%></option>
     	<%}%>
     	<%if(request.getAttribute("salesQuery")!=null){
    Sales sales = (Sales)request.getAttribute("salesQuery");%>
    <br>
     <h><%="for User: " + request.getAttribute("selectedUser")%></h>
     	
    <table>
    <tr>
    <td>Fees</td> <td>Total Sales</td><td></td> <td></td><td></td> <td></td>
    </tr>
    <tr>
    <td><%=sales.getFees() %></td> <td><%=sales.getSales()%></td><td></td> <td></td><td></td> <td></td>
    </tr>
    
    </table>
    <%} else {
    out.print("Please select a User"); 
    }  %>
     	
     	
    </select>
    
    <%if(request.getAttribute("salesQuery")!=null){
    Sales sales = (Sales)request.getAttribute("salesQuery");%>
     <br><h><%="for User: " + request.getAttribute("selectedUser")%></h>	
    <table>
    <tr>
    <td>Fees</td> <td>Total Sales</td><td></td> <td></td><td></td> <td></td>
    </tr>
    <tr>
    <td><%=sales.getFees() %></td> <td><%=sales.getSales()%></td><td></td> <td></td><td></td> <td></td>
    </tr>
    
    </table>
    <%} else {%>
    <br>
    <%
    out.print("Please select a User"); 
    }  %>
    
    <form action="?action=salestat" method="post">
    <input type="submit" value="Update">
    <input type="hidden" id="userselectedname" name="userselectedname">
    <input type="hidden" id="categoryselectedname" name="categoryselectedname">
    </form>
    
 </div>


</body>
</html>